//
//  CrazyChatSettingViewController.m
//  webSocket
//
//  Created by 马军凯 on 2019/1/29.
//  Copyright © 2019年 ZH. All rights reserved.
//

#import "CrazyChatSettingViewController.h"
#import "CrazyChatSettingOneCell.h"

@interface CrazyChatSettingViewController ()
<UITableViewDataSource,
UITableViewDelegate>

@end

@implementation CrazyChatSettingViewController

- (void)dealloc {
    NSLog(@"设置页面销毁");
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //创建tableView
    [self createTableView];
}

#pragma mark 创建UITableView
- (void)createTableView {
    _settingTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, CRAZY_SCREEN_WIDTH, CRAZY_SCREEN_HEIGHT - CRAZY_NAVIGATION_HEIGHT) style:UITableViewStylePlain];
    _settingTableView.dataSource = self;
    _settingTableView.delegate = self;
    _settingTableView.bounces = NO;
    _settingTableView.backgroundColor = CRAZY_RGBR(229);
    [_settingTableView registerClass:[CrazyChatSettingOneCell class] forCellReuseIdentifier:@"CrazyChatSettingOneCell"];
    [_settingTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
    [self.view addSubview:_settingTableView];
    _settingTableView.tableFooterView = [UIView new];
}

#pragma mark UITableView dataSource
//几组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
//每组个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
#pragma mark UITableView delegate
//cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        CrazyChatSettingOneCell *oneCell = [tableView dequeueReusableCellWithIdentifier:@"CrazyChatSettingOneCell"];
        if (oneCell == nil) {
            oneCell = [[CrazyChatSettingOneCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CrazyChatSettingOneCell"];
        }
        //赋值
        [oneCell setCellValueWithURL:self.shopHeadURL shopName:self.shopName];
        
        return oneCell;
    } else if (indexPath.row == 1) {
        UITableViewCell *twoCell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
        if (twoCell == nil) {
            twoCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
        }
        twoCell.selectionStyle = UITableViewCellSelectionStyleNone;
        twoCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        twoCell.textLabel.text = @"清除聊天记录";
        twoCell.textLabel.textColor = CRAZY_RGBR(33);
        twoCell.textLabel.font = [UIFont systemFontOfSize:13];
        
        return twoCell;
    } else {
        return nil;
    }
}
//cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return 100;
    } else if (indexPath.row == 1) {
        return 60;
    } else {
        return 0;
    }
}
#pragma mark separator 分割线
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    }
    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
        cell.preservesSuperviewLayoutMargins = NO;
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        cell.layoutMargins = UIEdgeInsetsZero;
    }
}
#pragma mark UITableView didselect
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row == 0) {
        [self clickGoToShop];
    }
    
    if (indexPath.row == 1) {
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否清除历史记录" preferredStyle:UIAlertControllerStyleAlert];
        //取消
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        [alertVC addAction:cancelAction];
        //确定
        UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alertVC addAction:sureAction];
        
        
        [self presentViewController:alertVC animated:YES completion:nil];
    }
}


- (void)clickGoToShop {
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
